<<<<<<< HEAD
<!--
 * @Author: Xia_cc 978487464@qq.com
 * @Date: 2022-06-08 17:56:52
 * @LastEditors: Xia_cc 978487464@qq.com
 * @LastEditTime: 2022-06-10 14:17:52
 * @FilePath: \vue 小U到家\src\views\Mainwuliao.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--  -->
<template>
  <el-container>
    <!-- 搜索框 -->
    <el-header>
      关键字:<el-input
        class="search"
        @change="selects()"
        type="text"
        placeholder="请输入内容"
        v-model="text"
      ></el-input>
      站点:<el-select
        class="search"
        @input="selects()"
        v-model="wuLiaoZhanDian"
        placeholder="请选择"
      >
        <el-option
          v-for="item in wuLiaoZhanDianArr"
          :key="item.value"
          :label="item.label"
          :value="item.value"
          size="mini"
        >
        </el-option>
      </el-select>
    </el-header>
    <!-- 弹出框 -->
    <el-dialog
      class="psyModle"
      title="添加物料"
      :visible.sync="wuLiaoAddVisible"
      width="37%"
      top="50px"
      center
    >
      <span class="psChaXunSpan">物料名称 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料名称"
        v-model="wuliaolei"
      ></el-input>
      <span class="psChaXunSpan">物料单位 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料单位"
        v-model="wuliaodanwei"
      ></el-input>
      <span class="psChaXunSpan">物料成本 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料成本"
        v-model="wuliaochenben"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wuLiaoAddVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="
            wuLiaoAddVisible = false;
            add();
          "
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      class="psyModle"
      title="编辑物料"
      :visible.sync="wuLiaoVisible"
      width="37%"
      top="50px"
      center
    >
      <span class="psChaXunSpan">物料名称 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料名称"
        v-model="wuliaolei"
      ></el-input>
      <span class="psChaXunSpan">物料单位 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料单位"
        v-model="wuliaodanwei"
      ></el-input>
      <span class="psChaXunSpan">物料成本 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料成本"
        v-model="wuliaochenben"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wuLiaoVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="
            wuLiaoVisible = false;
            updates();
          "
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 显示表 -->
    <el-main>
      <el-row>
        <el-button
          @click="
            wuLiaoAddVisible = true;
            add();
          "
          type="primary"
          plain
          >添加</el-button
        >
        <!-- <el-button @click="psyDelBut()" type="danger" plain>批量删除</el-button> -->
      </el-row>
      <Maintable :tableData="wuliaoArr">
        <template v-slot:tableline>
          <el-table-column prop="materials_name" label="物料名称" width="220"> </el-table-column>
          <el-table-column prop="materials_unit" label="单位" width="220"> </el-table-column>
          <el-table-column prop="materials_price" label="单间成本（元）" width="220">
          </el-table-column>
        </template>
        <template v-slot:chaozuo>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="success"
                slot="reference"
                plain
                icon="el-icon-view"
                title="查看"
                @click="chakan(scope.row.materials_id)"
              >
              </el-button>
              <el-button
                type="primary"
                plain
                icon="el-icon-edit"
                title="编辑"
                @click="chakan(scope.row.materials_id)"
              ></el-button>
              <el-button
                type="success"
                slot="reference"
                plain
                icon="el-icon-delete"
                title="删除"
                @click="chakan(scope.row.materialsId)"
              >
              </el-button>
            </template>
          </el-table-column>
        </template>
      </Maintable>
    </el-main>
    <el-footer>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[6, 8, 10, 12]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-footer>
  </el-container>
</template>

<script>
import Maintable from "../components/main/Maintable";

export default {
  name: "Mianwuliao",
  components: {
    Maintable,
  },
  computed: {},
  data() {
    return {
      text: "",
      size: 6,
      page: 1,
      total: 0,
      currentPage: 1,
      siteId: "",
      wuliaoArr: [],
      wuliaolei: "",
      materials_id: "",
      wuliaodanwei: "",
      materialsNum: "",
      wuliaochenben: "",
      materialsPrice: "",
      wuLiaoVisible: false,
      wuLiaoAddVisible: false,
      wuLiaoZhanDian: "",
      wuLiaoZhanDianArr: JSON.parse(window.localStorage.getItem("allzhandianArr")),
    };
  },
  methods: {
    handleSizeChange(val) {
      this.size = val;
      console.log(`每页 ${val} 条`);
      this.selects();
    },
    handleCurrentChange(val) {
      this.page = val;
      console.log(`当前页: ${val}`);
      this.selects();
    },
    //清空
    clears() {
      this.siteId = "";
      this.wuliaolei = "";
      this.materials_id = "";
      this.wuliaodanwei = "";
      this.materialsNum = "";
      this.wuliaochenben = "";
      this.materialsPrice = "";
      this.wuLiaoZhanDian = "";
    },
    //添加
    add() {
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/usermanager/insertMaterials",
        data: {
          materialsCost: this.wuliaochenben,
          // materials_id: this.materials_id,
          materialsName: this.wuliaolei,
          // materialsNum: this.materialsNum,
          // materialsPrice: this.materialsPrice,
          materialsUnit: this.wuliaodanwei,
          // siteId: this.siteId,
        },
      })
        .then((response) => {
          // console.log(response);
          // this.peisongyuanArr = response.data.data;
        })
        .catch((error) => {
          console.log(error);
        });
      this.selects();
    },
    //修改信息
    updatas() {
      var materials_id = window.localStorage.getItem("materials_id");
      this.zhandianArr.forEach((element) => {
        if (element.materials_id == materials_id) {
          this.$axios({
            method: "post",
            url: "/xiaoucomeshome_war/usermanager/updateMaterials",
            data: {
              materialsCost: this.wuliaochenben,
              // materialsId: this.materialsId,
              materialsName: this.wuliaolei,
              // materialsNum: this.materialsNum,
              // materialsPrice: this.materialsPrice,
              materialsUnit: this.wuliaodanwei,
              // siteId: this.siteId,
            },
          })
            .then((response) => {
              console.log(response);
              // this.zhandianArr = response.data.data;
            })
            .catch((error) => {
              console.log(error);
            });
        }
      });
      // this.$forceUpdate();
      this.selects();
      // console.log(id);
    },
    //删除弹出提示框
    psyDelBut(materials_id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          // console.log(id);
          this.deletes(materials_id);
          this.selects();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //查看
    chakan(materials_id) {
      window.localStorage.setItem("materialsId", materials_id);
      this.wuliaoArr.forEach((element) => {
        if (element.materials_id == materials_id) {
          // this.siteId = element.siteId;
          this.wuliaolei = element.materials_name;
          this.wuliaodanwei = element.materials_unit;
          this.materialsNum = element.materials_num;
          this.wuliaochenben = element.materials_cost;
          this.materialsPrice = element.materials_price;
          this.wuLiaoZhanDian = element.site_name;
        }
      });
    },
    //单个删除
    deletes(materials_id) {
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/usermanager/deleteMaterials",
        params: { materials_id },
      })
        .then((res) => {
          // console.log(res);
          // this.peisongyuanArr = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //获取页面数据
    selects() {
      // console.log(this.text);
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/usermanager/selectMaterialsAll",
        data: {
          materials_name: this.text,
          page: this.page,
          size: this.size,
          site_id: this.wuLiaoZhanDian,
        },
      })
        .then((response) => {
          this.total = response.data.total;
          this.wuliaoArr = response.data.data;
          // console.log(response.data);
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
  mounted() {
    this.selects();
  },
};
</script>

<style lang="less" scoped>
.block {
  margin: 0 130px;
  float: right;
}
.search {
  margin: 10px 40px 0 20px;
  width: 20%;
}
.psChaXunSpan {
  width: 20%;
  display: inline-block;
  margin: 5px 2%;
  text-align-last: justify;
}
.searchs {
  margin: 5px 2%;
  width: 72%;
}
</style>
=======
<!--
 * @Author: Xia_cc 978487464@qq.com
 * @Date: 2022-06-08 17:56:52
 * @LastEditors: Xia_cc 978487464@qq.com
 * @LastEditTime: 2022-06-10 14:17:52
 * @FilePath: \vue 小U到家\src\views\Mainwuliao.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--  -->
<template>
  <el-container>
    <!-- 搜索框 -->
    <el-header>
      关键字:<el-input
        class="search"
        @change="selects()"
        type="text"
        placeholder="请输入内容"
        v-model="text"
      ></el-input>
      站点:<el-select
        class="search"
        @input="selects()"
        v-model="wuLiaoZhanDian"
        placeholder="请选择"
      >
        <el-option
          v-for="item in wuLiaoZhanDianArr"
          :key="item.WLvalue"
          :label="item.WLlabel"
          :value="item.WLvalue"
          size="mini"
        >
        </el-option>
      </el-select>
    </el-header>
    <!-- 弹出框 -->
    <el-dialog
      class="psyModle"
      title="添加物料"
      :visible.sync="wuLiaoAddVisible"
      width="37%"
      top="50px"
      center
    >
      <span class="psChaXunSpan">物料名称 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料名称"
        v-model="wuliaolei"
      ></el-input>
      <span class="psChaXunSpan">物料单位 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料单位"
        v-model="wuliaodanwei"
      ></el-input>
      <span class="psChaXunSpan">物料成本 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料成本"
        v-model="wuliaochenben"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wuLiaoAddVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="
            wuLiaoAddVisible = false;
            add();
          "
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      class="psyModle"
      title="编辑物料"
      :visible.sync="wuLiaoVisible"
      width="37%"
      top="50px"
      center
    >
      <span class="psChaXunSpan">物料名称 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料名称"
        v-model="wuliaolei"
      ></el-input>
      <span class="psChaXunSpan">物料单位 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料单位"
        v-model="wuliaodanwei"
      ></el-input>
      <span class="psChaXunSpan">物料成本 </span
      ><el-input
        class="searchs"
        type="text"
        placeholder="请输入物料成本"
        v-model="wuliaochenben"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wuLiaoVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="
            wuLiaoVisible = false;
            updates();
          "
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 显示表 -->
    <el-main>
      <el-row>
        <el-button @click="wuLiaoAddVisible = true" type="primary" plain>添加</el-button>
        <!-- <el-button @click="psyDelBut()" type="danger" plain>批量删除</el-button> -->
      </el-row>
      <Maintable :tableData="wuliaoArr">
        <template v-slot:tableline>
          <el-table-column prop="date" label="物料名称" width="220"> </el-table-column>
          <el-table-column prop="name" label="单位" width="220"> </el-table-column>
          <el-table-column prop="date" label="单间成本（元）" width="220"> </el-table-column>
        </template>
        <template v-slot:chaozuo>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="success"
                slot="reference"
                plain
                icon="el-icon-view"
                title="查看"
                @click="chakan(scope.row.materialsId)"
              >
              </el-button>
              <el-button
                type="success"
                slot="reference"
                plain
                icon="el-icon-delete"
                title="删除"
                @click="chakan(scope.row.materialsId)"
              >
              </el-button>
            </template>
          </el-table-column>
        </template>
      </Maintable>
    </el-main>
  </el-container>
</template>

<script>
import Maintable from "../components/main/Maintable";

export default {
  name: "Mianwuliao",
  components: {
    Maintable,
  },
  computed: {},
  data() {
    return {
      text: "",
      siteId: "",
      wuliaoArr: [],
      wuliaolei: "",
      materialsId: "",
      wuliaodanwei: "",
      materialsNum: "",
      wuliaochenben: "",
      materialsPrice: "",
      wuLiaoVisible: false,
      wuLiaoAddVisible: false,
      wuLiaoZhanDian: "",
      wuLiaoZhanDianArr: [
        {
          WLvalue: "wl选项1",
          WLlabel: "青羊区",
        },
        {
          WLvalue: "wl选项2",
          WLlabel: "锦江区",
        },
        {
          WLvalue: "wl选项3",
          WLlabel: "温江区",
        },
      ],
    };
  },
  methods: {
    //清空
    clears() {
      this.siteId = "";
      this.wuliaolei = "";
      this.materialsId = "";
      this.wuliaodanwei = "";
      this.materialsNum = "";
      this.wuliaochenben = "";
      this.materialsPrice = "";
      this.wuLiaoZhanDian = "";
    },
    //添加
    add() {
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/usermanager/insertMaterials",
        data: {
          materialsCost: this.wuliaochenben,
          // materialsId: this.materialsId,
          materialsName: this.wuliaolei,
          // materialsNum: this.materialsNum,
          // materialsPrice: this.materialsPrice,
          materialsUnit: this.wuliaodanwei,
          // siteId: this.siteId,
        },
      })
        .then((response) => {
          // console.log(response);
          // this.peisongyuanArr = response.data.data;
        })
        .catch((error) => {
          console.log(error);
        });
      this.selects();
    },
    //修改信息
    updatas() {
      var materialsId = window.localStorage.getItem("materialsId");
      this.zhandianArr.forEach((element) => {
        if (element.materialsId == materialsId) {
          this.$axios({
            method: "post",
            url: "/xiaoucomeshome_war/usermanager/updateMaterials",
            data: {
              materialsCost: this.wuliaochenben,
              // materialsId: this.materialsId,
              materialsName: this.wuliaolei,
              // materialsNum: this.materialsNum,
              // materialsPrice: this.materialsPrice,
              materialsUnit: this.wuliaodanwei,
              // siteId: this.siteId,
            },
          })
            .then((response) => {
              console.log(response);
              // this.zhandianArr = response.data.data;
            })
            .catch((error) => {
              console.log(error);
            });
        }
      });
      // this.$forceUpdate();
      this.selects();
      // console.log(id);
    },
    //删除弹出提示框
    psyDelBut(materialsId) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          // console.log(id);
          this.deletes(materialsId);
          this.selects();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //查看
    chakan(materialsId) {
      window.localStorage.setItem("materialsId", materialsId);
      this.peisongyuanArr.forEach((element) => {
        if (element.materialsId == materialsId) {
          this.siteId = element.siteId;
          this.wuliaolei = element.materialsName;
          this.wuliaodanwei = element.materialsUnit;
          this.materialsNum = element.materialsNum;
          this.wuliaochenben = element.materialsCost;
          this.materialsPrice = element.materialsPrice;
          this.wuLiaoZhanDian = element.wuLiaoZhanDian;
        }
      });
    },
    //单个删除
    deletes(materialsId) {
      // console.log(phone);
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/usermanager/deleteMaterials",
        data: { materialsId },
      })
        .then((res) => {
          // console.log(res);
          // this.peisongyuanArr = res.data.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //获取页面数据
    selects() {
      // console.log(this.text);
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/admin/selectCourier",
        data: {
          materials_name: this.text,
          page: 1,
          size: 8,
          site_id: this.wuLiaoZhanDian,
        },
      })
        .then((response) => {
          this.wuliaoArr = response.data.data;
          // console.log(response.data);
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
  mounted() {
    this.selects();
  },
};
</script>

<style lang="less" scoped>
.search {
  margin: 10px 40px 0 20px;
  width: 20%;
}
.psChaXunSpan {
  width: 20%;
  display: inline-block;
  margin: 5px 2%;
  text-align-last: justify;
}
.searchs {
  margin: 5px 2%;
  width: 72%;
}
</style>
>>>>>>> ae27e4fe2d4f939d0b0ee2bfa506b9e3269c53cb
